class AIAssistant:
    """AI助手父类"""

    def __init__(self, assistant_id, name, assistant_type, version, online=False, score=0):
        self.assistant_id = assistant_id
        self.name = name
        self.assistant_type = assistant_type
        self.version = version
        self.online = online
        self.score = score

    def __str__(self):
        status = "🟢在线" if self.online else "🔴离线"
        return f"ID: {self.assistant_id}, 名称: {self.name}, 类型: {self.assistant_type}, 版本: {self.version}, 状态: {status}, 能力评分: {self.score} [{self.assistant_type}]"

    def start_service(self):
        """启动服务"""
        if not self.online:
            self.online = True
            return True
        return False

    def stop_service(self):
        """停止服务"""
        if self.online:
            self.online = False
            return True
        return False

    def execute_task(self, task):
        """执行任务"""
        if not self.online:
            return False, f"{self.name} 当前离线，无法执行任务。"
        return True, f"{self.name} 正在执行任务: {task}"


class DataAnalysisAssistant(AIAssistant):
    """数据分析助手"""

    def __init__(self, assistant_id, name, version, online=False, score=0, data_processing_speed=0):
        super().__init__(assistant_id, name, "数据分析助手", version, online, score)
        self.data_processing_speed = data_processing_speed  # 数据处理速度


class ImageGenerationAssistant(AIAssistant):
    """图片生成助手"""

    def __init__(self, assistant_id, name, version, online=False, score=0, image_quality="标准"):
        super().__init__(assistant_id, name, "图片生成助手", version, online, score)
        self.image_quality = image_quality  # 图片质量


class TextGenerationAssistant(AIAssistant):
    """文本生成助手"""

    def __init__(self, assistant_id, name, version, online=False, score=0, writing_style="通用"):
        super().__init__(assistant_id, name, "文本生成助手", version, online, score)
        self.writing_style = writing_style  # 写作风格


class TranslationAssistant(AIAssistant):
    """翻译助手"""

    def __init__(self, assistant_id, name, version, online=False, score=0, supported_languages=None):
        super().__init__(assistant_id, name, "翻译助手", version, online, score)
        self.supported_languages = supported_languages if supported_languages else ["中文", "英文"]  # 支持的语言


class VoiceAssistant(AIAssistant):
    """语音助手"""

    def __init__(self, assistant_id, name, version, online=False, score=0, voice_type="标准"):
        super().__init__(assistant_id, name, "语音助手", version, online, score)
        self.voice_type = voice_type  # 语音类型


class AIManager:
    """AI助手管理器"""

    def __init__(self, max_size=100):
        self.assistants = []
        self.max_size = max_size

    def add_assistant(self, assistant):
        """添加AI助手"""
        if len(self.assistants) >= self.max_size:
            print("❌ 助手数量已达上限，无法添加新助手！")
            return False

        # 检查ID是否重复
        for existing_assistant in self.assistants:
            if existing_assistant.assistant_id == assistant.assistant_id:
                print("❌ 助手ID已存在，请使用不同的ID！")
                return False

        self.assistants.append(assistant)
        print(f"✅ 助手【{assistant.name}】添加成功！")
        return True

    def delete_assistant(self, assistant_id):
        """删除AI助手"""
        for i, assistant in enumerate(self.assistants):
            if assistant.assistant_id == assistant_id:
                deleted_name = assistant.name
                del self.assistants[i]
                print(f"✅ 助手【{deleted_name}】已删除。")
                return True
        print("❌ 未找到指定ID的助手！")
        return False

    def find_assistant_by_id(self, assistant_id):
        """根据ID查找助手"""
        for assistant in self.assistants:
            if assistant.assistant_id == assistant_id:
                return assistant
        return None

    def show_all_assistants(self):
        """显示所有助手列表"""
        if not self.assistants:
            print("当前没有AI助手。")
            return

        print("所有AI助手列表：")
        for i, assistant in enumerate(self.assistants, 1):
            print(f"{i}. {assistant}")

    def show_assistant_details(self, assistant_id):
        """显示助手详情"""
        assistant = self.find_assistant_by_id(assistant_id)
        if assistant:
            print(f"✅ 查询结果: {assistant}")
        else:
            print("❌ 未找到指定ID的助手！")

    def modify_assistant(self, assistant_id, attribute, value):
        """修改助手属性"""
        assistant = self.find_assistant_by_id(assistant_id)
        if not assistant:
            print("❌ 未找到指定ID的助手！")
            return False

        attribute = attribute.lower()
        if attribute == "name":
            assistant.name = value
        elif attribute == "type":
            assistant.assistant_type = value
        elif attribute == "version":
            assistant.version = value
        elif attribute == "online":
            assistant.online = value.lower() in ["true", "1", "是", "yes"]
        elif attribute == "score":
            try:
                assistant.score = int(value)
            except ValueError:
                print("❌ 能力评分必须是数字！")
                return False
        else:
            print("❌ 无效的属性名！")
            return False

        print(f"✅ 助手【{assistant_id}】修改成功！")
        return True

    def start_assistant_service(self, assistant_id):
        """启动助手服务"""
        assistant = self.find_assistant_by_id(assistant_id)
        if not assistant:
            print("❌ 未找到指定ID的助手！")
            return False

        if assistant.start_service():
            print(f"✅ 助手【{assistant.name}】已启动。")
        else:
            print(f"助手【{assistant.name}】已在运行。")
        return True

    def stop_assistant_service(self, assistant_id):
        """停止助手服务"""
        assistant = self.find_assistant_by_id(assistant_id)
        if not assistant:
            print("❌ 未找到指定ID的助手！")
            return False

        if assistant.stop_service():
            print(f"✅ 助手【{assistant.name}】已停止。")
        else:
            print(f"助手【{assistant.name}】已处于停止状态。")
        return True

    def assign_task(self, assistant_id, task):
        """分配任务"""
        assistant = self.find_assistant_by_id(assistant_id)
        if not assistant:
            print("❌ 未找到指定ID的助手！")
            return False

        success, message = assistant.execute_task(task)
        if success:
            print(f"✅ {message}")
        else:
            print(f"❌ {message}")
        return success

    def show_statistics(self):
        """显示系统统计信息"""
        if not self.assistants:
            print("当前没有AI助手。")
            return

        total_count = len(self.assistants)
        online_count = sum(1 for assistant in self.assistants if assistant.online)
        offline_count = total_count - online_count
        avg_score = sum(assistant.score for assistant in self.assistants) / total_count

        print("系统统计信息：")
        print(f"总助手数: {total_count}")
        print(f"在线助手数: {online_count}")
        print(f"离线助手数: {offline_count}")
        print(f"平均能力评分: {avg_score:.2f}")


def create_sample_assistants():
    """创建示例助手"""
    manager = AIManager()

    # 添加示例助手
    sample_assistants = [
        VoiceAssistant(101, "小智", "v1.2", True, 85),
        TextGenerationAssistant(102, "文小助", "v2.0", True, 92),
        ImageGenerationAssistant(103, "图灵", "v1.5", False, 88),
        DataAnalysisAssistant(104, "数小析", "v1.0", True, 79),
        TranslationAssistant(105, "翻译精灵", "v2.1", False, 95)
    ]

    for assistant in sample_assistants:
        manager.add_assistant(assistant)

    return manager


def main():
    """主程序"""
    manager = create_sample_assistants()

    while True:
        print("\n" + "=" * 40 + " AI助手管理器 " + "=" * 40)
        print("1. 查看所有AI助手列表")
        print("2. 根据ID查询助手详情")
        print("3. 添加新的AI助手")
        print("4. 根据ID修改助手信息")
        print("5. 删除AI助手（按ID）")
        print("6. 启动AI助手服务")
        print("7. 停止AI助手服务")
        print("8. 为AI助手分配任务")
        print("9. 显示系统统计信息")
        print("0. 退出系统")
        print("=" * 93)

        choice = input("请选择操作: ").strip()

        if choice == "0":
            print("感谢使用AI助手管理器，再见！")
            break

        elif choice == "1":
            manager.show_all_assistants()

        elif choice == "2":
            assistant_id = input("请输入要查询的AI助手ID: ").strip()
            try:
                assistant_id = int(assistant_id)
                manager.show_assistant_details(assistant_id)
            except ValueError:
                print("❌ ID必须是数字！")

        elif choice == "3":
            print("添加新AI助手")
            try:
                assistant_id = int(input("请输入ID: ").strip())
                name = input("请输入名称: ").strip()
                assistant_type = input("请输入类型: ").strip()
                version = input("请输入版本号: ").strip()
                online_input = input("是否在线？(1-是, 0-否): ").strip()
                online = online_input in ["1", "是", "yes", "true"]
                score = int(input("请输入能力评分(0-100): ").strip())

                # 根据类型创建对应的助手子类
                if assistant_type == "数据分析助手":
                    new_assistant = DataAnalysisAssistant(assistant_id, name, version, online, score)
                elif assistant_type == "图片生成助手":
                    new_assistant = ImageGenerationAssistant(assistant_id, name, version, online, score)
                elif assistant_type == "文本生成助手":
                    new_assistant = TextGenerationAssistant(assistant_id, name, version, online, score)
                elif assistant_type == "翻译助手":
                    new_assistant = TranslationAssistant(assistant_id, name, version, online, score)
                elif assistant_type == "语音助手":
                    new_assistant = VoiceAssistant(assistant_id, name, version, online, score)
                else:
                    new_assistant = AIAssistant(assistant_id, name, assistant_type, version, online, score)

                manager.add_assistant(new_assistant)
            except ValueError:
                print("❌ 输入格式错误，请确保ID和能力评分为数字！")

        elif choice == "4":
            print("修改AI助手数据")
            try:
                assistant_id = int(input("请输入ID: ").strip())
                print("可修改属性列表为：name, type, version, online, score")
                input_data = input("请输入要修改的属性和值，用空格分割: ").strip().split()

                if len(input_data) >= 2:
                    attribute = input_data[0]
                    value = " ".join(input_data[1:])
                    manager.modify_assistant(assistant_id, attribute, value)
                else:
                    print("❌ 输入格式错误！")
            except ValueError:
                print("❌ ID必须是数字！")

        elif choice == "5":
            try:
                assistant_id = int(input("请输入要删除的AI助手ID: ").strip())
                manager.delete_assistant(assistant_id)
            except ValueError:
                print("❌ ID必须是数字！")

        elif choice == "6":
            try:
                assistant_id = int(input("请输入要启动的AI助手ID: ").strip())
                manager.start_assistant_service(assistant_id)
            except ValueError:
                print("❌ ID必须是数字！")

        elif choice == "7":
            try:
                assistant_id = int(input("请输入要停止的AI助手ID: ").strip())
                manager.stop_assistant_service(assistant_id)
            except ValueError:
                print("❌ ID必须是数字！")

        elif choice == "8":
            try:
                assistant_id = int(input("请输入目标AI助手ID: ").strip())
                task = input("请输入任务内容: ").strip()
                manager.assign_task(assistant_id, task)
            except ValueError:
                print("❌ ID必须是数字！")

        elif choice == "9":
            manager.show_statistics()

        else:
            print("❌ 无效的选择，请重新输入！")

        input("\n按回车键继续...")


if __name__ == "__main__":
    main()